namespace Moment.Models;

using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

public partial class MenuItem
{
    [JsonProperty("CommandType")] public string CommandType { get; set; }

    [JsonProperty("Group")] public string Group { get; set; }

    [JsonProperty("Icon")] public string Icon { get; set; }

    [JsonProperty("Items")] public MenuItem[] Items { get; set; }

    /// <summary>
    /// 菜单是否激活状态
    /// </summary>
    [JsonProperty("IsActive")]
    public bool? IsActive { get; set; }

    [JsonProperty("Key")] public string Key { get; set; }

    [JsonProperty("LocaleKey")] public string LocaleKey { get; set; }
    
    [JsonProperty("GroupLocaleKey", NullValueHandling = NullValueHandling.Ignore)]
    public string GroupLocaleKey { get; set; }
}

public partial class MenuItem
{
    public static MenuItem[] FromJson(string json) =>
        JsonConvert.DeserializeObject<MenuItem[]>(json, Moment.Models.Converter.Settings);
}

public static class Serialize
{
    public static string ToJson(this MenuItem[] self) =>
        JsonConvert.SerializeObject(self, Moment.Models.Converter.Settings);
}

internal static class Converter
{
    public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
    {
        MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
        DateParseHandling = DateParseHandling.None,
        Converters =
        {
            new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
        },
    };
}